/**
 * Class containing the tit-for-two-tats strategy.
 * @author	081028AW
 */
public class StrategyXOR2Moves extends Strategy
   {
  /**
   * Encoding for tit-for-tat strategy.
   */
   int opponent2ndLastMove = 1;
   int my2ndLastMove = 1;
   //int moveNum;
   public String simpleStratMoves;
   //int simpleStratMoves[];
   int currMove;
   public String simpleStrat;
   //public int simpleStrat[]; 

  // 0 = defect, 1 = cooperate

   public StrategyXOR2Moves()
	{
		name = "2Moves";
		currMove = 0;
		//moveNum = 25;
		/*for(int i = 0; i < moveNum; i++)
		{
			//simpleStratMoves[i] = simpleStrat[i];
			simpleStratMoves[i] = 0;
		}*/
	}  /* StrategySimple */

   /*public void getCurrStrat(int[] currStrat)
   {
	simpleStratMoves = currStrat;
   }*/

   public void getCurrStrat(String currStrat)
   {
	simpleStratMoves = currStrat;
   }

   public void getCurrLength(int currLength)
   {
	moveNum = currLength;
   }
   
   public void saveOpponentMove(int move)  
   { 
	   opponent2ndLastMove = opponentLastMove;
	   opponentLastMove = move; 
   }
   
   public void saveMyMove(int move)  
   {
	   my2ndLastMove = myLastMove; 
	   myLastMove = move;
   }
   

   public int nextMove()
   {
	   if(currMove >= moveNum-1)
	   {
		   currMove = 0;
	   }
	   else
	   {
		   currMove++;
	   }
	   
	   return xor(xor(xor(opponentLastMove, opponent2ndLastMove), xor(myLastMove, my2ndLastMove)), Character.digit(simpleStratMoves.charAt(currMove), 10));
	   
	   //return Character.digit(simpleStratMoves.charAt(currMove), 10);

   }  /* nextMove */
   
   
	public int xor(int val1, int val2)
	{
		boolean v1 = false;
		boolean v2 = false;
		
		if(val1 == 1)
			v1 = true;
		if(val2 == 1)
			v2 = true;
		
		//So if v1 is a 1 and v2 is a 0, then xor gives a 1.
		//The same result comes about when v1 is a 0 and v2 is a 1.
		if(((v1 == true) && (v2 == false)) || ((v1 == false) && (v2 == true)))
			return 1;
		//If v1 and v2 are either both 1's or both 0's, then the result is a 0.
		else
			return 0;
	}

   }  /* class StrategyTitForTwoTats */

